package com.ch.home.controller.gameController;

import com.ch.home.bean.GameRepository;
import com.ch.home.service.serviceImpl.gameServiceImpl.GameRepositoryServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * 答题拦截器
 * Created by CHEN on 2019/8/23.
 */
@RestController
@RequestMapping("/game/examination")
public class ExaminationController {

    @Autowired
    GameRepositoryServiceImpl gameRepositoryService;

    @PostMapping("/get")
    public HashMap getQusetion() {

        HashMap<Object, Object> result;

        result = gameRepositoryService.getRandomQuestion( );

        return result;
    }


    @PostMapping("/add")
    public HashMap addQuestion(@RequestParam(required = false) String questionUrl,
                               @RequestParam(required = false) String questionContent,
                               @RequestParam(required = false) String option1,
                               @RequestParam(required = false) String option2,
                               @RequestParam(required = false) String answer) {

        HashMap<Object, Object> result;
        result = gameRepositoryService.addQuestion(new GameRepository(null, questionUrl, questionContent, option1, option2, answer));
        return result;
    }

    @PostMapping("/addMul")
    public HashMap addMulQuestion(@RequestParam(value = "questionUrl", required = false) ArrayList<String> questionUrl,
                                  @RequestParam(value = "questionContent", required = false) ArrayList<String> questionContent,
                                  @RequestParam(value = "option1", required = false) ArrayList<String> option1,
                                  @RequestParam(value = "option2", required = false) ArrayList<String> option2,
                                  @RequestParam(value = "answer", required = false) ArrayList<String> answer) {

        HashMap<Object, Object> result;

        result = gameRepositoryService.transferAndAdd(questionUrl, questionContent, option1, option2, answer);
        return result;
    }
    @PostMapping("/update")
    public HashMap updateQuestion(@RequestParam(required = false) Integer questionId,
                                  @RequestParam(required = false) String questionUrl,
                                  @RequestParam(required = false) String questionContent,
                                  @RequestParam(required = false) String option1,
                                  @RequestParam(required = false) String option2,
                                  @RequestParam(required = false) String answer){

        HashMap<Object, Object> result;

        result=gameRepositoryService.UpdateQuestion(new GameRepository(questionId,questionUrl,questionContent,option1,option2,answer));
        return result;

    }


}
